<?php

namespace api\modules\v1\controllers\marketing;

use Yii;
use api\controllers\OnAuthController;
use common\models\marketing\RiskType;
use common\helpers\CommonHelper;

/**
 * Class RiskTypeController
 * @package api\modules\v1\controllers\marketing
 */
class RiskTypeController extends OnAuthController
{
    /**
     * @var RiskType
     */
    public $modelClass = RiskType::class;

    /**
     * @api {get} /v1/marketing/risk-type/index 风控类型列表
     * @apiName index
     * @apiGroup RiskType
     */
    public function actionIndexRiskType()
    {
        $params = Yii::$app->request->get();
        $params['project_id'] = $this->projectId;

        // 查询结果
        $data = Yii::$app->services->marketingRiskType->getList($params);

        return $data;
    }

    /**
     * @api {post} /v1/marketing/risk_type/create 新增风控类型
     * @apiName create
     * @apiGroup RiskType
     *
     * @apiParam {String} name              风控类型名称
     * @apiParam {Number} status            【1启用、0停用】
     */
    public function actionCreateRiskType()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;

        return Yii::$app->services->marketingRiskType->create($params);
    }

    /**
     * @api {post} /v1/marketing/risk_type/update 编辑风控类型
     * @apiName update
     * @apiGroup RiskType
     *
     * @apiParam {Number} id                风控类型ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateRiskType()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;
        return Yii::$app->services->marketingRiskType->update($params);
    }


    /**
     * @api {post} /v1/marketing/risk_type/update-status 编辑风控类型的状态
     * @apiName update-status
     * @apiGroup RiskType
     *
     * @apiParam {Number} id                风控类型ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateRiskTypeStatus()
    {
        $id = Yii::$app->request->post('id');
        $status = Yii::$app->request->post('status');

        return Yii::$app->services->marketingRiskType->updateStatus($id, $status);
    }

    /**
     * @api {post} /v1/marketing/risk-type/delete 删除风控类型
     * @apiName delete
     * @apiGroup RiskType
     *
     * @apiParam {Number} id                风控类型ID
     */
    public function actionDeleteRiskType()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->marketingRiskType->delete($id);
    }

    /**
     * @api {post} /v1/marketing/risk-type/true-delete 删除风控类型
     * @apiName delete
     * @apiGroup RiskType
     *
     * @apiParam {Number} id                风控类型ID
     */
    public function actionTrueDeleteRiskType()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->marketingRiskType->trueDelete($id);
    }


}